package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import androidx.appcompat.widget.AppCompatTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.AfterSalesListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.app.util.SettingUtil
import com.gexiaobao.pigeon.databinding.ItemAfterSalesBinding
import com.makeramen.roundedimageview.RoundedImageView
import java.math.BigDecimal

/**
 * @Author      : hxw
 * @Date        : 2023/7/6 15:45
 * @Describe    :
 */
class AfterSalesAdapter(data: ArrayList<AfterSalesListResponse.ListGoods>) :
    BaseQuickAdapter<AfterSalesListResponse.ListGoods, DataBindBaseViewHolder>(R.layout.item_after_sales, data) {

    @SuppressLint("SetTextI18n", "NotifyDataSetChanged")
    override fun convert(holder: DataBindBaseViewHolder, item: AfterSalesListResponse.ListGoods) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemAfterSalesBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val itemGoodsImage = holder.getView<RoundedImageView>(R.id.ivItemMyGoodsOrderImageIcon)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.specImg, itemGoodsImage, 10, R.drawable.shop_product_def)
        val tvAfterSales = holder.getView<AppCompatTextView>(R.id.tvItemAfterSales)
        when (item.orderStatus) {
            11 -> {
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.Return_details))//退货详情
                tvAfterSales.isClickable = true
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#F44336"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_red_to_pay)
            }

            7 -> {
                tvAfterSales.isClickable = false
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.Refund_successful))//退款成功
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#999999"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_radio_button_gray)
            }

            12 -> {
                tvAfterSales.isClickable = false
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.Successful_return))//退货成功
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#999999"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_radio_button_gray)
            }

            13 -> {
                tvAfterSales.isClickable = true
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.Return_failure))//退货失败
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#F44336"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_red_to_pay)
            }

            14 -> {
                tvAfterSales.isClickable = true
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.Return_details))//退货详情
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#F44336"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_red_to_pay)
            }

            15 -> {//退货审核通过
                tvAfterSales.isClickable = true
                holder.setText(R.id.tvItemAfterSales, context.getString(R.string.out_information))//我已寄出
                holder.setTextColor(R.id.tvItemAfterSales, Color.parseColor("#F44336"))
                holder.setBackgroundResource(R.id.tvItemAfterSales, R.drawable.border_red_to_pay)
            }
        }

        val tvItemPriceTotal = holder.getView<AppCompatTextView>(R.id.itemPrice)
        var totalPrice = BigDecimal("0.00")
        val price = BigDecimal(item.salePrice.toString())
        val count = BigDecimal(item.amount.toString())
        val result = price.multiply(count)
        totalPrice = totalPrice.add(result)
        SettingUtil.setPrice(totalPrice.toString(), tvItemPriceTotal, 50, Color.BLACK)
    }
}